//
//  NMarketManger.m
//  NMFramework
//
//  Created by 刘琛 on 2019/3/19.
//  Copyright © 2019年 刘琛. All rights reserved.
//

#import "NMarketManger.h"
#import "NetworkAddress.h"
#import "DeviceInfo.h"
#import "iSeeNetworkRequest.h"
#import "ISeeUserInfoModel.h"
#import <MJExtension/MJExtension.h>

@interface NMarketManger ()

@property (nonatomic, copy) NMarketMangerFaildBlock failed;

@end


@implementation NMarketManger

static NSString* const HCGFReqBody = @"body";




+ (void)initWithPhoneNumber:(NSString *)phone faild:( NMarketMangerFaildBlock)fail{
    
    
    
    NSMutableDictionary *dic =[[NSMutableDictionary alloc] init];
    [dic setObject:phone forKey:@"userMobile"];
    [dic setObject:[DeviceInfo deviceModelName] forKey:@"deviceModel"];
    
    [iSeeNetworkRequest getUrl:[NSString stringWithFormat:@"%@%@", NMarketMainUrl, NoPasswordLogin] params:dic success:^(id object) {
        
        NSString *session = object[@"body"][@"session"];
        ISeeUserInfoModel *userInfo = [ISeeUserInfoModel mj_objectWithKeyValues:object[@"body"][@"userInfo"]];
        
        [[NSUserDefaults standardUserDefaults] setObject:[userInfo mj_JSONString] forKey:NMarketUserInfo];
        
        [[NSUserDefaults standardUserDefaults] setObject:session forKey:NMarketUserSession];
        [[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:NMarketLoginStatus];
    } failure:^(NSError *error) {
        [[NSUserDefaults standardUserDefaults] setObject:@"0" forKey:NMarketLoginStatus];
        fail(error);
    }];
}




@end
